import Nprogress from 'nprogress';
import 'nprogress/nprogress.css'; // progress bar style
import store from '@/store';
import vm from '../index';

export default {
  showLoading(to, from, next) {
    Nprogress.start();
    next();
  },

  auth(to, form, next) {
    const userInfo = store.state.user.userInfo;

    // 获取用户信息
    if (to.path !== '/login' && !userInfo) {
      vm.replace({
        path: '/login',
        query: {
          redirect: vm.currentRoute.fullPath,
        },
      });
      next();
    } else {
      next();
    }
  },
};
